//
//  WebViewController.h
//  DectorDemo
//
//  Created by ank on 2022/4/15.
//

#import <UIKit/UIKit.h>

#define ECLogEnable

@class ECWebViewController;

/// webview delegate
@protocol ECWebViewDeleate <NSObject>

/**
 *  XMWebview加载完成是否成功
 */
- (void)webview:(ECWebViewController *_Nonnull)webView didFinishRequesResult:(BOOL)isSuccess;

/**
  *  XMWebview获取H5的title
  */
- (void)webview:(ECWebViewController *_Nonnull)webView loadWebTitle:(NSString *_Nullable)webTitle;

/**
 *  XMWebview点击返回的方法
 */
- (void)webview:(ECWebViewController *_Nonnull)webView backWithParameter:(NSDictionary *_Nullable)parameter;

/**
 *  XMWebview点击打开新的webView页面
 *  @param url       webPage Url
 *  @param title     webPage Title 有值用本地导航栏,无值不用导航栏
 *  @param parameter webPage Parameter  控制器参数
 */
- (void)webview:(ECWebViewController *_Nonnull)webView startWebPageWithUrl:(NSString *_Nonnull)url andWebTitle:(NSString *_Nullable)title andParameter:(NSDictionary *_Nullable)parameter;

@end


typedef void (^ECHandler)(id _Nullable data);



@interface ECWebViewController : UIViewController

/// 背景图
@property (nonatomic, strong) UIView * _Nullable bgView;
@property (nonatomic, weak) id<ECWebViewDeleate> _Nullable delegate;


- (void)loadUrl:(NSString *_Nonnull)urlStr;
- (void)loadRequest:(NSURLRequest *_Nonnull)request;
- (void)loadHtml:(NSString *_Nonnull)html baseURL:(nullable NSURL *)baseURL;

- (void)registerHandler:(NSString *_Nonnull)handlerName handler:(ECHandler _Nullable )handler;
- (void)deleteHandler:(NSString *_Nonnull)handlerName;

- (void)callHandler:(NSString *_Nonnull)handlerName data:(id _Nullable)data;
- (void)evaluateJavaScript:(NSString *_Nonnull)javaScriptString;
@end
